<?php
include_once "library/OAuthStore.php";
include_once "library/OAuthRequester.php";

function getOAuthToken()
{
	$key = 'DZ36yHdU1GPQTJpxFBbTfg'; // this is your consumer key
	$secret = 'o5geTAKqySmNOoRTSJHrv99ZxzA3F1CRVwQNUTy5yF0'; // this is your secret key

	// register at http://twitter.com/oauth_clients and fill these two 
	define("TWITTER_CONSUMER_KEY", $key);
	define("TWITTER_CONSUMER_SECRET", $secret);

	define("TWITTER_OAUTH_HOST","https://twitter.com");
	define("TWITTER_REQUEST_TOKEN_URL", TWITTER_OAUTH_HOST . "/oauth/request_token");
	define("TWITTER_AUTHORIZE_URL", TWITTER_OAUTH_HOST . "/oauth/authorize");
	define("TWITTER_ACCESS_TOKEN_URL", TWITTER_OAUTH_HOST . "/oauth/access_token");

	define('OAUTH_TMP_DIR', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_ENV["TMP"])); 

	// Twitter test
	$options = array('consumer_key' => TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET, 'callback' => 'http://174.94.35.37/Projects/purgatory/Template%20Project/signin.php');
	OAuthStore::instance("2Leg", $options);

	try
	{
		// Obtain a request object for the request we want to make
		$request = new OAuthRequester(TWITTER_REQUEST_TOKEN_URL, "POST", $options);
		$result = $request->doRequest(0);
		parse_str($result['body'], $params);
		//print_r($result);
		return $params['oauth_token'];
	
	}
	catch(OAuthException2 $e)
	{
		echo "Exception" . $e->getMessage();
	}
}
?>
